import Vue from 'vue'
import Vuex from 'vuex'
import shoppingCart from './shoppingCart/shoppingCart';

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
  },
  
  getters:{
    getAllCount(state){
      var total = 0;
      state.shoppingCart.items.forEach((element)=>{
        //判断是否为选中商品
        if(element.checked){
          total+=element.count;
        } 
      })
      return total;
    },
    getTotalPrice(state){
      var total = 0;
      state.shoppingCart.items.forEach((element)=>{
        //判断是否为选中商品
        if(element.checked){
          total+=(element.count*element.price);
        } 
      })
      return total;
    }
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    shoppingCart:shoppingCart
  }
})
